package mytool;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Criteria;
import android.os.Handler;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;


import activitys.Base_stationActivity;
import activitys.MainActivity;
import tool.ducong.com.mygpsdemo.MyAPP;
import tool.ducong.com.mygpsdemo.R;

/**
 * Created by zerdoor_pc on 2016/3/14.
 */
public class MyDialog {
    public static void showCustomDialog(final Activity activity, final TextView font_size) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        // 获取自定义布局的对象
        View view = LayoutInflater.from(activity).inflate(R.layout.mydialog_font_item,
                null);
        TextView out = (TextView) view.findViewById(R.id.font_dialog_out);
        final LinearLayout font_big_ll = (LinearLayout) view.findViewById(R.id.font_big_ll);
        final LinearLayout font_mid_ll = (LinearLayout) view.findViewById(R.id.font_mid_ll);
        final LinearLayout font_small_ll = (LinearLayout) view.findViewById(R.id.font_small_ll);
        final TextView font_big = (TextView) view.findViewById(R.id.font_big);
        final TextView font_mid = (TextView) view.findViewById(R.id.font_mid);
        final TextView font_small = (TextView) view.findViewById(R.id.font_small);

        builder.setView(view);

        // 给对话框加“确认”和“取消”按钮

        final AlertDialog dialog = builder.create();
        out.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });


        font_big_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                font_big.setTextColor(0xff4450d4);
                font_small.setTextColor(0xffbbbbbb);
                font_mid.setTextColor(0xffbbbbbb);
                font_size.setText("高");
                setPower(Criteria.POWER_HIGH);
                ShardPreferencesTool.saveshare(activity,"MyAPP.POWER",Criteria.POWER_HIGH);
                dialog.cancel();
            }
        });
        font_small_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                font_small.setTextColor(0xff4450d4);
                font_mid.setTextColor(0xffbbbbbb);
                font_big.setTextColor(0xffbbbbbb);

                font_size.setText("低");
                setPower(Criteria.POWER_LOW);
                ShardPreferencesTool.saveshare(activity, "MyAPP.POWER", Criteria.POWER_LOW);
                dialog.cancel();

            }
        });
        font_mid_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                font_mid.setTextColor(0xff4450d4);
                font_small.setTextColor(0xffbbbbbb);
                font_big.setTextColor(0xffbbbbbb);

                font_size.setText("中");
                setPower(Criteria.POWER_MEDIUM);
                ShardPreferencesTool.saveshare(activity, "MyAPP.POWER", Criteria.POWER_MEDIUM);
                dialog.cancel();
            }
        });
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

    }
    private static void setPower(int power){
        MyAPP.POWER=power;
        MainActivity.gps_tool.setTimes();
    }

    public static void inputPassword(final Activity con, final Handler handler){
        final EditText editText = new EditText(con);
        editText.setSingleLine();
        editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
//                        editText.setBackgroundResource(R.drawable.edittext1);
        new AlertDialog.Builder(con)
                .setTitle("请输入密码")
                .setView(editText)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        int nick_name = Integer.parseInt(editText.getText().toString());
                        if (nick_name == 123456) {
                            handler.sendEmptyMessage(0);
                        } else {
                            ToastShow.showShort(con,"密码输入有误!");
                        }

                    }
                })
                .setNegativeButton("取消", null)
                .show();
    }
}
